package com.ssy.lingxi.marketing.serviceimpl.component.activity;

import cn.hutool.core.text.StrFormatter;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

/**
 * 活动商品字符常量
 * @author yzc
 * @version 2.0.0
 * @date 2021/11/23
 */
public interface ActivityStrPool {

    DecimalFormat decimalFormat = new DecimalFormat("#.#");
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    String comma_zh = "，";
    String semicolon_zh = "；";

    // ===================商品的活动标签activityTag===================
    String specialOffer_at = "特价";
    String plummet_at = "直降";
    String discount_at = "{}折";
    String full_quantity_reduction_at = "满量减";
    String full_quantity_discount_at = "满量折";
    String full_money_pt_reduction_at = "跨店满减";
    String full_money_pt_discount_at = "跨店满折";
    String full_money_at_reduction_at = "满额减";
    String full_money_at_discount_at = "满额折";
    String give_goods_at = "赠品";
    String give_coupon_at = "返券";
    String morePiece_at = "第{}件{}折";
    String combination_at = "{}元场";
    String groupPurchase_at = "拼团";
    String bargain_at = "砍价";
    String swap_at = "换购";
    String secKill_at = "秒杀";
    String pre_sell_at = "预售";
    String setMeal_at = "套餐";
    String attempt_at = "试用";

    // ===================商品活动优惠标签preferentialTag===================
    String specialOffer_pt = specialOffer_at;
    String plummet_pt = plummet_at;
    String discount_pt = "直降{}折";
    String full_quantity_reduction_pt = full_quantity_reduction_at;
    String full_quantity_discount_pt = full_quantity_discount_at;
    String full_money_pt_reduction_pt = full_money_pt_reduction_at;
    String full_money_pt_discount_pt = full_money_pt_discount_at;
    String full_money_at_reduction_pt = full_money_at_reduction_at;
    String full_money_at_discount_pt = full_money_at_discount_at;
    String give_goods_pt = "赠品";
    String give_coupon_pt = "返券";
    String morePiece_pt = "多买优惠";
    String combination_pt = combination_at;
    String groupPurchase_pt = groupPurchase_at;
    String bargain_pt = bargain_at;
    String swap_pt = swap_at;
    String secKill_pt = "限时秒杀";
    String pre_sell_pt = pre_sell_at;
    String setMeal_pt = setMeal_at;
    String attempt_pt = attempt_at;

    // ===================商品活动优惠标签描述preferentialTagDesc===================
    String specialOffer_ptd = "活动截止：{}，抢购抓紧";
    String plummet_ptd = specialOffer_ptd;
    String discount_ptd = specialOffer_ptd;
    String full_quantity_reduction_ptd = "满{}件，总价减{}元";
    String full_quantity_discount_ptd = "满{}件，总价打{}折";
    String full_money_reduction_ptd = "满{}元，减{}元";
    String full_money_discount_ptd = "满{}元，打{}折";
    String give_goods_ptd_full_money_1 = "满{}元赠";
    String give_goods_ptd_full_money_2 = "{}{}件";
    String give_coupon_ptd_full_money_1 = "满{}元返";
    String give_coupon_ptd_full_money_2 = "{}{}张";
    String give_goods_ptd_buy_goods_1 = "购买{}件赠";
    String give_goods_ptd_buy_goods_2 = "{}{}件";
    String give_coupon_ptd_buy_goods_1 = "购买{}件返";
    String give_coupon_ptd_buy_goods_2 = "{}{}张";
    String morePiece_ptd = "第{}件{}折";
    String combination_ptd = "{}元{}件";
    String groupPurchase_ptd = "{}人团";
    String swap_full_money_ptd = "满{}元可优惠换购{}";
    String swap_buy_goods_ptd = "购买{}件可优惠换购{}";
    String secKill_ptd = specialOffer_ptd;

    // ===================活动描述===================

    String specialOffer_desc = "以下商品限时特价，抓紧抢购";
    String plummet_desc = "以下商品限时直降，抓紧抢购";
    String discount_desc = "以下商品限时折扣，抓紧抢购";

    /**
     * 模板字符串格式化
     * @param str 模板
     * @param args 参数
     * @return 返回结果
     */
    default String strFormat(String str, Object... args) {
        return StrFormatter.format(str, args);
    }

    /**
     * 格式化时间戳
     * @param millisecond 时间戳
     * @return 返回结果
     */
    default String millisecondToDateStr(Long millisecond) {
        return LocalDateTime.ofInstant(Instant.ofEpochMilli(millisecond), ZoneId.systemDefault()).format(dateTimeFormatter);
    }

    /**
     * 格式化小数
     * @param decimal 参数
     * @return 返回结果
     */
    default String decimalFormatStr(BigDecimal decimal) {
        return decimalFormat.format(decimal).trim();
    }

    /**
     * 百位数转换为十位数
     * 折扣在数据库存的1-100
     * 99.9折 -> 9.99折
     * 88折 -> 8.8折
     * @param decimal 参数
     * @return 返回结果
     */
    default BigDecimal hundredToTen(BigDecimal decimal) {
        return decimal.divide(BigDecimal.TEN, 3, RoundingMode.HALF_UP);
    }

    /**
     * 百位数转换为小数
     * 99.9折 -> 0.999
     * 88折 -> 0.88
     * @param decimal 参数
     * @return 返回结果
     */
    default BigDecimal hundredToDecimal(BigDecimal decimal) {
        return decimal.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP);
    }

    /**
     * 两数相除
     * @param decimal1 参数
     * @param decimal2 参数
     * @return 返回结果
     */
    default BigDecimal div(BigDecimal decimal1, BigDecimal decimal2) {
        return decimal1.divide(decimal2, 3, RoundingMode.HALF_UP);
    }
}
